package com.bodacn.keypoint.adapter;

import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.bodacn.keypoint.R;
import com.bodacn.keypoint.bean.ClothPieceCheckLeft;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ClothPieceSearchLeftLvAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<ClothPieceCheckLeft> list;
    private DecimalFormat fnum;

    public ClothPieceSearchLeftLvAdapter(List<ClothPieceCheckLeft> list, Context context) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.list = list;
        fnum = new DecimalFormat("##0.0");
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHodler;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cloth_piece_check_left, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        if (list.size() > 0) {
            ClothPieceCheckLeft clothPieceCheckLeft = list.get(position);
            viewHodler.tvData.setText(clothPieceCheckLeft.getAddDate());
            viewHodler.tvHuohao.setText(clothPieceCheckLeft.getGoodsNo());
            viewHodler.tvHyh.setText(clothPieceCheckLeft.getOrderNo());
            viewHodler.tvPo.setText(clothPieceCheckLeft.getPO());
            viewHodler.tvSize.setText(clothPieceCheckLeft.getSize());
            viewHodler.tvStyle.setText(clothPieceCheckLeft.getStyle());
            viewHodler.tvColor.setText(clothPieceCheckLeft.getColor());
        }

        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.tv_data)
        TextView tvData;
        @BindView(R.id.tv_hyh)
        TextView tvHyh;
        @BindView(R.id.tv_huohao)
        TextView tvHuohao;
        @BindView(R.id.tv_po)
        TextView tvPo;
        @BindView(R.id.tv_size)
        TextView tvSize;
        @BindView(R.id.tv_style)
        TextView tvStyle;
        @BindView(R.id.tv_color)
        TextView tvColor;
        @BindView(R.id.mylistitem)
        LinearLayout mylistitem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
